package com.jeesite.modules.utils;

import java.util.Calendar;
import java.util.Date;

import com.jeesite.common.lang.DateUtils;

public class DateUtil extends DateUtils{
	
	/**
	 * 获取月头
	 * @param date
	 * @return
	 */
	public static Date getOfMonthFirst(Date date) {
		if (date == null) {
			return null;
		} else {
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(5,1);  
			calendar.set(11, 0);
			calendar.set(12, 0);
			calendar.set(13, 0);
			calendar.set(14, 0);
			return calendar.getTime();
		}
	}

	/**
	 * 获取月末
	 * @param date
	 * @return
	 */
	public static Date getOfMonthLast(Date date) {
		if (date == null) {
			return null;
		} else {
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(5,getMonthHasDays(date));  
			calendar.set(11, 23);
			calendar.set(12, 59);
			calendar.set(13, 59);
			calendar.set(14, 999);
			return calendar.getTime();
		}
	}
	
	public static Date getOfDayFirst(Date date) {
		if (date == null) {
			return null;
		} else {
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(11, 0);
			calendar.set(12, 0);
			calendar.set(13, 0);
			calendar.set(14, 0);
			return calendar.getTime();
		}
	}

	public static Date getOfDayLast(Date date) {
		if (date == null) {
			return null;
		} else {
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(11, 23);
			calendar.set(12, 59);
			calendar.set(13, 59);
			calendar.set(14, 999);
			return calendar.getTime();
		}
	}
	
	public static void main(String []args){
		Date start = getOfMonthFirst(new Date());
		Date end = getOfMonthLast(new Date());
		
		System.out.println(DateUtil.formatDateTime(start));
		System.out.println(DateUtil.formatDateTime(end));
	}
}
